# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=statsmodels
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-$_realname"
         "${MINGW_PACKAGE_PREFIX}-python3-$_realname")
pkgver=0.6.1
pkgrel=2
pkgdesc="Statistical computations and models for use with SciPy (mingw-w64)"
arch=('any')
url="http://statsmodels.sourceforge.net/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-scipy"
             "${MINGW_PACKAGE_PREFIX}-python3-scipy"
             "${MINGW_PACKAGE_PREFIX}-python2-pandas"
             "${MINGW_PACKAGE_PREFIX}-python3-pandas"
             "${MINGW_PACKAGE_PREFIX}-python2-patsy"
             "${MINGW_PACKAGE_PREFIX}-python3-patsy"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cython2"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cython2"
             "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://pypi.python.org/packages/source/s/statsmodels/statsmodels-${pkgver}.tar.gz")
sha256sums=('be4e44374aec9e848b73e5a230dee190ac0c4519e1d40f69a5813190b13ec676')

prepare() {
  cp -a ${_realname}-${pkgver} ${_realname}-py2-${pkgver}
  cp -a ${_realname}-${pkgver} ${_realname}-py3-${pkgver}

  cd ${_realname}-py2-${pkgver}
  sed -e "s|#![ ]*/usr/bin/python$|#!/usr/bin/python2|" \
      -e "s|#![ ]*/usr/bin/env python$|#!/usr/bin/env python2|" \
      -e "s|#![ ]*/bin/env python$|#!/usr/bin/env python2|" \
      -i $(find . -name '*.py')
}

build() {
  # build for python2
  cd ${srcdir}/${_realname}-py2-${pkgver}

  # regenerate Cython files
  #MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  #${MINGW_PREFIX}/bin/python2 setup.py clean

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # build for python3
  cd ${srcdir}/${_realname}-py3-${pkgver}

  # regenerate Cython files
  #MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  #${MINGW_PREFIX}/bin/python3 setup.py clean

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-statsmodels() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-scipy"
           "${MINGW_PACKAGE_PREFIX}-python2-pandas"
           "${MINGW_PACKAGE_PREFIX}-python2-patsy")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-nose: needed for integrated test suite"
              "${MINGW_PACKAGE_PREFIX}-python2-matplotlib: needed for plotting functions")

  cd ${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE.txt"
}

package_python3-statsmodels() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-scipy"
           "${MINGW_PACKAGE_PREFIX}-python3-pandas"
           "${MINGW_PACKAGE_PREFIX}-python3-patsy")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-nose: needed for integrated test suite"
              "${MINGW_PACKAGE_PREFIX}-python3-matplotlib: needed for plotting functions")

  cd ${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE.txt"
}

package_mingw-w64-i686-python2-statsmodels() {
  package_python2-statsmodels
}

package_mingw-w64-i686-python3-statsmodels() {
  package_python3-statsmodels
}

package_mingw-w64-x86_64-python2-statsmodels() {
  package_python2-statsmodels
}

package_mingw-w64-x86_64-python3-statsmodels() {
  package_python3-statsmodels
}
